<?php
/**
 * @file
 * JavaScript for filter module.
 *
 * Usage:
 *  - A page that wants to use this JavaScript file should link to this file
 *    using the '<script></script>' tags once and only once.
 *
 * Parameter(s):
 *  - None.
 *
 * Global variable(s) set:
 *  - None.
 *
 * Global variable(s) unset:
 *  - None.
 *
 * Exception(s):
 *  - None.
 *
 * This file includes/requires:
 *  - h_greenindeed.php
 *  - h_filter.php
 */

// header file(s) ==============================================================
require_once "h_greenindeed.php";
require_once "h_filter.php";


// implementation ==============================================================
?>
// <script> // to induce syntax highlighting on netbeans

// global variable(s) ----------------------------------------------------------
var foFilter = null;  //!< The filter form object.


// implementation --------------------------------------------------------------
/**
 * Initializes the filter module.
 *
 * @param ftn
 *    The function to call when the 'refresh' button is clicked or when the
 *    'rows per page' select box is updated.
 */
function filter_init(ftn) {
  // initialize form object
  foFilter = document.<?php echo NAME_FILTER_FORM ?>;

  // onclick event binding for 'refresh' button (jquery)
  $(".<?php echo CSS_CLASS_BUTTON_REFRESH ?>").click(function () {
    ftn();
    return false;
  });
  // onchange event binding for 'rows per page' select box (jquery)
  $(".<?php echo CSS_CLASS_SELECT_ROWSPP ?>").change(function () {
    ftn();
    return false;
  });
}

/**
 * Get the filter mask.
 *
 * @return
 *    The filter mask.
 */
function filter_getMask() {
  var filterMask = 0;
  // search for checked checkboxes
  for (var i = 0; i < foFilter.<?php echo NAME_FILTER_FIELD_MASK ?>.length; i++)
  {
    // retreive checkbox
    var filter = foFilter.<?php echo NAME_FILTER_FIELD_MASK ?>[i];
    if (filter.checked) {
      // checkbox is checked => add value to mask
      filterMask += parseInt(filter.value);
    }
  }
  return filterMask;
}

/**
 * Get the number of rows per page.
 *
 * @return
 *    The number of rows per page.
 */
function filter_getRowsPP() {
  return foFilter.<?php echo NAME_FILTER_FIELD_ROWSPP ?>.value;
}

// </script> // to induce syntax highlighting on netbeans
